package com.hq.fxh.No5_User.User.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.CustomerView.CircleImageView;
import com.hq.fxh.Modle.FavotityListGetModle;
import com.hq.fxh.R;
import com.hq.fxh.Utils.AppConstant;
import com.hq.fxh.Utils.GlideUtils;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.Utils.Tool;

import java.util.List;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/15
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_MyShouCang extends BaseAdapter {

    List<FavotityListGetModle.DataBean> data;

    public void setData(List<FavotityListGetModle.DataBean> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {

        LogUtils.e(" position==" + position);
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_shoucang_newitem, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (data != null && data.size() > position) {
            FavotityListGetModle.DataBean dataBean = data.get(position);

            int favorites_type = dataBean.getFavorites_type();
            switch (favorites_type) {
                case 1:
                    viewHolder.layoutNewFrom.setVisibility(View.VISIBLE);
                    viewHolder.layoutAuthor.setVisibility(View.GONE);
                    viewHolder.imageItemVideoTag.setVisibility(View.GONE);


                    break;
                case 2:
                    viewHolder.layoutNewFrom.setVisibility(View.GONE);
                    viewHolder.layoutAuthor.setVisibility(View.VISIBLE);
                    viewHolder.imageItemVideoTag.setVisibility(View.GONE);

                    Tool.setUrlToHeadImage(parent.getContext(), dataBean.getHead_url(), viewHolder.authorIcon);
                    Tool.setStringToText(viewHolder.authorName, dataBean.getNickname());
                    break;
                case 3:
                    viewHolder.layoutNewFrom.setVisibility(View.GONE);
                    viewHolder.layoutAuthor.setVisibility(View.VISIBLE);
                    viewHolder.imageItemVideoTag.setVisibility(View.VISIBLE);

                    Tool.setUrlToHeadImage(parent.getContext(), dataBean.getHead_url(), viewHolder.authorIcon);
                    Tool.setStringToText(viewHolder.authorName, dataBean.getNickname());
                    break;

            }
            String title_pic = dataBean.getTitle_pic();

            if (title_pic == null || title_pic.equals("")) {
                viewHolder.layoutPic.setVisibility(View.GONE);
            } else {
                viewHolder.layoutPic.setVisibility(View.VISIBLE);

                GlideUtils.loadImageView(parent.getContext(), title_pic, viewHolder.newImageView);

            }
            Tool.setStringToText(viewHolder.textTitle, dataBean.getTitle());


        } else {
            GlideUtils.loadImageView(parent.getContext(), AppConstant.imageUrl, viewHolder.newImageView);
        }


        return view;


    }


    static class ViewHolder {
        protected TextView textTitle;
        protected TextView tvNewfrom;
        protected LinearLayout layoutNewFrom;
        protected CircleImageView authorIcon;
        protected TextView authorName;
        protected LinearLayout layoutAuthor;
        protected TextView btnDelFavorite;
        protected ImageView newImageView;
        protected ImageView imageItemVideoTag;
        protected LinearLayout layoutPic;
        protected LinearLayout newsType1;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            textTitle = (TextView) rootView.findViewById(R.id.text_title);
            tvNewfrom = (TextView) rootView.findViewById(R.id.tv_newfrom);
            layoutNewFrom = (LinearLayout) rootView.findViewById(R.id.layout_NewFrom);
            authorIcon = (CircleImageView) rootView.findViewById(R.id.author_icon);
            authorName = (TextView) rootView.findViewById(R.id.author_name);
            layoutAuthor = (LinearLayout) rootView.findViewById(R.id.layout_author);
            btnDelFavorite = (TextView) rootView.findViewById(R.id.btn_delFavorite);
            newImageView = (ImageView) rootView.findViewById(R.id.new_imageView);
            imageItemVideoTag = (ImageView) rootView.findViewById(R.id.image_Item_VideoTag);
            layoutPic = (LinearLayout) rootView.findViewById(R.id.layout_Pic);
            newsType1 = (LinearLayout) rootView.findViewById(R.id.newsType1);
        }
    }
}
